﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Sistema_de_Taller.SDT_UI.Replacement
{
	public partial class replacement_default : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

        protected void validateID(Object source,  System.Web.UI.WebControls.ServerValidateEventArgs args)
        {
            MessageOk.Visible = false;
            SDT_DAL.Utilities.Replacement_DAL Repuesto = new SDT_DAL.Utilities.Replacement_DAL();
            args.IsValid = !Repuesto.ReplacementIdExist(Convert.ToUInt32(txtID.Text));
            
            if (args.IsValid)
            {
                Common_Files.Definitions.Remplacement Remplacement = new Common_Files.Definitions.Remplacement();

                Remplacement.Replacement_ID = txtID.Text;
                Remplacement.Replacement_Name = txtName.Text;
                Remplacement.Replacement_Brand = txtBrand.Text;
                Remplacement.Replacement_Stock = Convert.ToUInt32(txtStock.Text);
                if (txtOutput.Text.Length == 0) txtOutput.Text = "0";
                Remplacement.Replacement_Output = Convert.ToUInt32(txtOutput.Text);
                Remplacement.Replacement_Location = txtLocation.Text;

                SDT_BS.Replacement_BS replacement_bs = new SDT_BS.Replacement_BS();

                lblMessages.Text = "Repuesto cargado satisfactoriamente";
                MessageOk.Visible = true;

                replacement_bs.validate(Remplacement);

            }
            
        }
	}
}